//
//  RecordDetailViewController.m
//  MagicCardDemo
//
//  Created by 向恒 on 15/7/5.
//  Copyright (c) 2015年 向恒. All rights reserved.
//

#import "RecordDetailViewController.h"
#import "AppDelegate.h"
#import "CardSerialize.h"
@interface RecordDetailViewController ()

@end

@implementation RecordDetailViewController
@synthesize txtviewDetail;
//@synthesize editingIndexPath;
//@synthesize selectRowNo;
//@synthesize detail;
@synthesize time;
static NSInteger selectRowNo;

+(void)setSelectRowNo:(NSInteger)num
{
    selectRowNo =num;
}

//- (IBAction)finshed:(id)sender {
//    [self dismissModalViewControllerAnimated:TRUE];
//}

//进入联系记录详细页面
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    // Do any additional setup after loading the view.
    AppDelegate* ad = [UIApplication sharedApplication].delegate;  //需要使用公用的数据。
    //detail.text = @"";  //一开始清空文本，因为上面有我做标记的文本：“RecordsDetail”
    //NSInteger row =editingIndexPath.row;
    NSInteger row = selectRowNo;
    NSString* file =  [ad.recordFileList objectAtIndex:row];
    CardQueue* recordQueue = [CardData ReadDataFromFile:file];
    
    [txtviewDetail setText:@""];
    
    NSMutableString * str = @"";
    //NSMutableString * str = [[NSMutableString alloc]init];
    //不知道ios里面是否有foreach之类的用法，那样方便些
    //后面可能需要研究一下Label的分行现实的。
    //现在如果记录长度超过有一定值就现实不出来了。
    //for(int i = 0;i < ad.cardData.TrainQueue.arrCards.count;i++)
    for(int i = 0;i < recordQueue.arrCards.count;i++)
    {
        NSNumber * num = [recordQueue.arrCards objectAtIndex:i];
        NSString * strNum = [NSString stringWithFormat:@"%@",num];
        //str =
        //[str stringByAppendingString:[detail text]];  //string拼接了之后为什么不需要接受一下。而下面的拼接strNum则需要
        //因为上行代码什么乱用都没有。所以无所谓。
        //str = [str stringByAppendingString:detail.text];
        str = [str stringByAppendingString:strNum];
        if(i<recordQueue.arrCards.count-1)
            str = [str stringByAppendingString:@","];
        //自动换行,10个数字一行
        if((i+1)%10 == 0)
            str = [str stringByAppendingString:@"\n"];
    }
    //detail.text = str;
    
    [txtviewDetail setText:str];
    
    time.text = recordQueue.date;
    
    //左滑退出详细页面
    UISwipeGestureRecognizer* gr = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
    [gr setDirection:(UISwipeGestureRecognizerDirectionRight)];
    [[self view] addGestureRecognizer:gr];
}


//手势响应函数
-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer
{
    if(recognizer.direction==UISwipeGestureRecognizerDirectionRight)
    {
        NSLog(@"gesture left ");
        //希望这里能够回到上一级
        //[self dismissModalViewControllerAnimated:TRUE];
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
